package cn.woochen.comlib.util

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context

/**
 * 剪切板工具类
 */
object ClipboardUtil {
    fun copyToClipboard(context: Context, text: String?,block:()->Unit = {}) {
        if (text.isNullOrBlank()) return
        val clipboardManager = context.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
        val clip = ClipData.newPlainText("Label", text)
        clipboardManager.setPrimaryClip(clip)
        block.invoke()
    }
}